﻿// MenuState.s
// Author: Gant Briseno
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Casters.source.Managers;
#endregion

namespace Casters.source.States
{
    public class CMenuState : CBaseState
    {
        protected Texture2D m_tTitle = null;
        protected Vector2 m_vTitlePos;

        protected Texture2D m_tMenuWindow = null;
        protected Rectangle m_rMenuWindowPos;

        protected SpriteFont m_font;

        protected Vector2 m_CameraOffset;

        int testing = 0;

        // Singleton access
        public static CMenuState instance = null;
        static public CMenuState GetInstance()
        {
            if (instance == null)
                instance = new CMenuState();

            return instance;
        }

        public CMenuState() { }

        /// <summary>
        /// Setup the state
        /// </summary>
        public override void Initialize()
        {
            m_CameraOffset = CGame.GetInstance().m_Camera.m_vPosition;

            Vector2 screenCenter = new Vector2(CGame.GetInstance().viewPort.X * 0.5f, CGame.GetInstance().viewPort.Y * 0.5f);
            m_rMenuWindowPos = new Rectangle(0, 0, 400, 500);
            m_rMenuWindowPos.X = (int)((screenCenter.X - m_rMenuWindowPos.Width * 0.5f) + m_CameraOffset.X);
            m_rMenuWindowPos.Y = (int)((screenCenter.Y - m_rMenuWindowPos.Height * 0.5f) + m_CameraOffset.Y);

        }

        /// <summary>
        /// Loads images and register for events
        /// </summary>
        public override void LoadContent()
        {
            if(m_tTitle == null)
                m_tTitle = CGame.GetInstance().Content.Load<Texture2D>("Menu/square");
            if(m_font == null)
                m_font = CGame.GetInstance().Content.Load<SpriteFont>("Fonts/Arial");
            if (m_tMenuWindow == null)
                m_tMenuWindow = CGame.GetInstance().Content.Load<Texture2D>("Menu/menu_window");

            // Register Events
            CEventSystem.RegisterEventHandler(EventID.Confirm, OnConfirm);
        }

        /// <summary>
        /// Unregister events
        /// </summary>
        public override void UnloadContent()
        {
            // Unregister Events
            CEventSystem.UnregisterEventHandler(EventID.Confirm, OnConfirm);
        }

        /// <summary>
        /// Update stuff
        /// </summary>
        /// <param name="dt"><Delta Time/param>
        public override void Update(float dt)
        {
        }

        /// <summary>
        /// Draws Everything to the screen
        /// </summary>
        public override void Draw()
        {
            CRenderEngine.Draw(m_tMenuWindow, m_rMenuWindowPos, Color.Wheat);
            CRenderEngine.DrawString(m_font, "# of Test Events: " + testing.ToString(), new Vector2(900f, 100f) + m_CameraOffset, Color.Red);
            CRenderEngine.DrawString(m_font, "Battle State!\nPressEnter!", new Vector2(600.0f, 500.0f) + m_CameraOffset, Color.White);
            CRenderEngine.Draw(m_tTitle, Vector2.Zero - m_CameraOffset, Color.White);
        }

        /****************
         * input events *
         ****************/
        public void OnConfirm(params object[] eventArgs)
        {
            CEventSystem.BroadcastEvent(EventID.ChangeState, CClassState.GetInstance());
        }

        public void OnBack(params object[] eventArgs)
        {
        }

        public void OnUp(params object[] eventArgs)
        {
        }

        public void OnDown(params object[] eventArgs)
        {
        }

        public void OnLeft(params object[] eventArgs)
        {
        }

        public void OnRight(params object[] eventArgs)
        {
        }
    }
}
